<?php 
class M_Admin extends MY_Model{
    function __construct(){
        parent::__construct();
		$this->load->database();
    }
    public function login($user, $pass){
        $pass=$this->cry($pass);
        //$this->db->where()
        $var=$this->db->get_where("tb_admin",array('name'=>$user,"pass"=>$pass));   
        $qr=$var->result_array(); 
        if(count($qr)){
            foreach($var->result_array() as $kq){
                 //$data=$kq['name'];
                 $newdata = array(
                   'username'  =>$kq['name'],
                   'email'     =>$kq['email'],
                   'logged_in' => TRUE
               );
               $this->session->set_userdata($newdata);
                return $newdata;         
            }  
        }        
    }
    public function logged_in(){
        return (bool) $this->session->userdata('logged_in');
    }
    public function logout(){
        $this->session->sess_destroy();
    }
    public function conf(){
        
        
        
    }
	//lấy danh sách phân loại
	public function get_menu_product(){
       $query = $this->db->query("select * from tb_menu_product");
		return $query->result_array();
    }
	//lấy danh sách đơn vị
	public function get_unit(){
       $query = $this->db->query("select * from tb_unit");
		return $query->result_array();
    }
	public function get_product(){
       $query = $this->db->query("select * from tb_product ORDER BY id_product DESC");
		return $query->result_array();
    }
    
}
?>